"""
浏览一个需要登录才能查看的url
1)请求头从包含COOKIE信息
f12--network 找到请求头user——agent，cookie
2）cookies参数
"""
import requests

# 1 直接对含有参数的url发起请求
url = 'https://baidu.com/s?wd=python'
h={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
# 'Cookie':'user_locale=zh-CN; oschina_new_user=false; gitee-session-n=ZXVENE10SndkdXVGT2J3YkYzYUJLVVdiS0xBK1lGTTFJeGpQVW1acHBtN2Y4VHVyd2lvMHpudE90dEMybjA2bmNaaGJTbkJDckNZYTdRY2Vyamx0blZGeDhwbDB5S1A2bUovM0pxeTh0dW5lZDZnT1NrWWlkUEFsc3orRGhoNUhYaUhUcit2TWE3N3ZOcjRselBma25SUGZOS3E3aVVpbzlXRGFaaXowOFNpWFNnL0tCcVFtMzdieE5ubEcxcXlkLS1ISzRTZG9obHVObWhNTUJaTVNqb2tnPT0%3D--b9e51b97d2e41cdaed41811b1ad72a5a8a3ac89e; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1605766208; Hm_lpvt_24f17767262929947cc3631f99bfd274=1605766208; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22175df1fd9fda01-001ec6fc60b8d-333769-2073600-175df1fd9fec76%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.baidu.com%2Flink%22%7D%2C%22%24device_id%22%3A%22175df1fd9fda01-001ec6fc60b8d-333769-2073600-175df1fd9fec76%22%7D'
}
r=requests.get(url,headers=h)
print(r.content.decode())

# h={
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
#
# }
# str_cookies='user_locale=zh-CN; oschina_new_user=false; gitee-session-n=ZXVENE10SndkdXVGT2J3YkYzYUJLVVdiS0xBK1lGTTFJeGpQVW1acHBtN2Y4VHVyd2lvMHpudE90dEMybjA2bmNaaGJTbkJDckNZYTdRY2Vyamx0blZGeDhwbDB5S1A2bUovM0pxeTh0dW5lZDZnT1NrWWlkUEFsc3orRGhoNUhYaUhUcit2TWE3N3ZOcjRselBma25SUGZOS3E3aVVpbzlXRGFaaXowOFNpWFNnL0tCcVFtMzdieE5ubEcxcXlkLS1ISzRTZG9obHVObWhNTUJaTVNqb2tnPT0%3D--b9e51b97d2e41cdaed41811b1ad72a5a8a3ac89e; tz=Asia%2FShanghai; Hm_lvt_24f17767262929947cc3631f99bfd274=1605766208; Hm_lpvt_24f17767262929947cc3631f99bfd274=1605766208; sajssdk_2015_cross_new_user=1; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22175df1fd9fda01-001ec6fc60b8d-333769-2073600-175df1fd9fec76%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.baidu.com%2Flink%22%7D%2C%22%24device_id%22%3A%22175df1fd9fda01-001ec6fc60b8d-333769-2073600-175df1fd9fec76%22%7D'
# dict_cookies={}
# r=requests.get(url,h,cookies=dict_cookies)
# print(r.content.decode())